Data is stored in Box and on GitHub (via git lfs) .
The Box data may not be as up-to-date as the GitHub data!
GitHub data https://github.com/Yoyomanzoor/RNA-SEQualizer/blob/master/code/R/fGSEA_plots/fGSEA_plot_results.rds
Box data https://uchicago.box.com/s/airudr2c9mqpfragkteh13cedh8dblnu
Requires ggplot2 and ggpubr which can be installed with:
For interactive graphs, you will also need plotly:
Load packages
reqpkg <- c("ggplot2", "ggpubr")
for (i in reqpkg) {
library(i, quietly=T, warn.conflicts=F, character.only=T)
}
theme_set(theme_pubr())For interactive graphs, you will also need plotly:
fGSEA was run comparing WT SPF vs GF, KO SPF vs GF, SPF WT vs KO, and GF WT vs KO at all timepoints and timepoints 1-6 using three databases (hallmark, KEGG, and GO). The results of fGSEA were stored in a large list, f_res, which is saved to fGSEA_results.RData. Below is the data structure for f_res:
# f_res
# | - WT # WT SPF vs GF comparisons
# | | - time_all
# | | | - hm
# | | | | - list(pathway, pval, padj, ES, NES, nMoreExtreme, size, list(leadingEdge))
# | | | - KEGG
# | | | - GO
# | | - time_1
# | | - time_2
# | | - time_3
# | | - time_4
# | | - time_5
# | | - time_6
# | - KO
# | - SPF
# | - GFThis data can be loaded with:
Plots were all generated using a custom blanket create_plot function (see fgsea_filtering.R). Plot results are saved to fGSEA_plot_results.rds. Below is the data structure for plot_res:
# | - WT # WT SPF vs GF comparisons
# | | - time_all
# | | | - hm
# | | | | - immune
# | | | | | - (ggplot data)
# | | | | - cancer
# | | | | - ox_phos
# | | | | - glucose
# | | | | - carb
# | | | | - lipid
# | | | | - bile
# | | | | - peroxisome
# | | | | - protein
# | | | | - nucleic
# | | | | - scfa
# | | | | - metabolism
# | | | - KEGG
# | | | - GO
# | | - time_1
# | | - time_2
# | | - time_3
# | | - time_4
# | | - time_5
# | | - time_6
# | - KO
# | - SPF
# | - GFThis data can be loaded with:
This command may take a moment due to the large size of the data!
plot_arrange <- function(..., ncol, nrow, labels, top) {
ggarrange(..., ncol = ncol, nrow = nrow, labels = labels, font.label = list(size=10, face="plain"), hjust = 0.5, label.x = 0.5) %>%
annotate_figure(top = text_grob(top, face = "bold", size = 14),
left = text_grob("pathways", rot = 90),
bottom = text_grob("Normalized Enrichment Score"))
}plotly_arrange <- function(plots, nrows = 1, labels, top) {
for (i in length(plots)) {
plots[[i]] %<>% ggplotly() %>% layout(
title = top,
xaxis = list(title = "Normalized Enrichment Score"),
yaxis = list(title = "pathways"),
annotations = list(text = labels[[i]], x = 0.5, y = 1, xref = 'paper', yref = 'paper', showarrow = F))
}
subplot(plots)
}To view a single plot, it can simply be called from the plot_res list.
For example, to view the results for WT SPF vs GF using all timepoints and the hallmark database with the immune filter:
All plots are unlabelled so that they could be arranged and labelled accordingly in grids. Only specific timepoints have the timepoint labelled.
To add labels to a plot, you can use the plot_arrange function.
The function takes 4 parameters. nrow and ncol are the number of rows and columns to arrange graphs. labels are the labels for each graph, in the order that they are given to the function, and top is the title of the entire grid.
Since this is just one graph, we only need one row and column.
nrow = 1
ncol = 1
labels = "immune pathways"
top = "WT SPF vs GF, all timepoints, hallmark"
plot_arrange(plot_res$WT$time_all$hm$immune, ncol = ncol, nrow = nrow, labels = labels, top = top)To view multiple plots, you can use the plot_arrange function.
Each plot is given to the function and labelled in order of submission. The number of columns and rows need to be given to the function.
To view the results for WT SPF vs GF using the hallmark database with the immune filter with all timepoints arranged on a single graph:
nrow = 2
ncol = 3
labels = ""
top = "WT SPF vs GF, hallmark. Immune pathways over time."
plot_arrange(plot_res$WT$time_1$hm$immune, plot_res$WT$time_2$hm$immune, plot_res$WT$time_3$hm$immune, plot_res$WT$time_4$hm$immune, plot_res$WT$time_5$hm$immune, plot_res$WT$time_6$hm$immune,
ncol = ncol, nrow = nrow, labels = labels, top = top)For every timepoint graph, the graphs already have a time label.
To view the results for WT SPF vs GF using all timepoints with the immune filter, comparing the hallmark, KEGG, and GO databases:
nrow = 1
ncol = 3
labels = c("Hallmark", "KEGG", "GO")
top = "WT SPF vs GF, all timepoints. Immune pathways between databases."
plot_arrange(plot_res$WT$time_all$hm$immune, plot_res$WT$time_all$KEGG$immune, plot_res$WT$time_all$GO$immune,
ncol = ncol, nrow = nrow, labels = labels, top = top)To view the results for WT SPF vs GF using all timepoints and the KEGG database, comparing the immune, cancer, and metabolism filters:
nrow = 1
ncol = 3
labels = c("immune", "cancer", "metabolism")
top = "WT SPF vs GF, all timepoints, KEGG"
plot_arrange(plot_res$WT$time_all$KEGG$immune, plot_res$WT$time_all$KEGG$cancer, plot_res$WT$time_all$KEGG$metabolism,
ncol = ncol, nrow = nrow, labels = labels, top = top)Interactive plots can be generated via plotly, which shows the pathways and their NES score when the cursor hovers over the plot.
plot_arrange does not work with plotly objects.
plotly_arrange allows for labelling much like plot_arrange.
nrow <- 1
labels <- "immune"
top <- "WT SPF vs GF, all timepoints, hallmark"
plotly_arrange(list(plot_res$WT$time_all$hm$immune),
nrows = nrow, labels = labels, top = top)This is UNTESTED because plotly stopped working on my computer and I don’t want to change my R environment until I finish the shiny app!
plotly_arrange also allows for multiple plots to be shown at once.
nrow <- 1
labels <- c("immune", "cancer")
top <- "WT SPF vs GF, all timepoints, hallmark"
plotly_arrange(list(plot_res$WT$time_all$hm$immune, plot_res$WT$time_all$hm$cancer),
nrows = nrow, labels = labels, top = top)This is UNTESTED because plotly stopped working on my computer and I don’t want to change my R environment until I finish the shiny app!
## R version 3.6.3 (2020-02-29)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18362)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] plotly_4.9.2.1 ggpubr_0.2.5 magrittr_1.5 ggplot2_3.3.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.4.6 pillar_1.4.3 compiler_3.6.3 tools_3.6.3
## [5] digest_0.6.25 viridisLite_0.3.0 jsonlite_1.6.1 evaluate_0.14
## [9] lifecycle_0.2.0 tibble_2.1.3 gtable_0.3.0 pkgconfig_2.0.3
## [13] rlang_0.4.5 crosstalk_1.1.0.1 yaml_2.2.1 xfun_0.12
## [17] gridExtra_2.3 withr_2.1.2 stringr_1.4.0 dplyr_0.8.5
## [21] httr_1.4.1 knitr_1.28 vctrs_0.2.4 htmlwidgets_1.5.1
## [25] cowplot_1.0.0 grid_3.6.3 tidyselect_1.0.0 glue_1.3.2
## [29] data.table_1.12.8 R6_2.4.1 rmarkdown_2.1 farver_2.0.3
## [33] tidyr_1.0.2 purrr_0.3.3 scales_1.1.0 htmltools_0.4.0
## [37] assertthat_0.2.1 colorspace_1.4-1 ggsignif_0.6.0 labeling_0.3
## [41] stringi_1.4.6 klippy_0.0.0.9500 lazyeval_0.2.2 munsell_0.5.0
## [45] crayon_1.3.4
smanzoor@uchicago.edu